<extend name="Public/header" />
<block name="main">
<div class="panel panel-default">
    <div class="panel-heading">
        DataTables Advanced Tables                 
    </div>

                        <!-- /.panel-heading -->
    <div class="panel-body">
        <div id="dataTables-example_wrapper" class="dataTables_wrapper form-inline dt-bootstrap no-footer">
            <div class="row">
                <form role="form" action="{:U('index')}" method="get" enctype="multipart/form-data">
                    <div class="col-sm-6">
                    </div>
                    <div class="form-group input-group">
                        <input type="text" class="form-control" name="selname" value="关键字">
                        <span class="input-group-btn">
                                                <button type="submit" class="btn btn-default" ><i class="fa fa-search"></i>
                                                </button>
                                            </span>
                    </div>
                </form>
            </div>
        <div class="row">
            <div class="col-sm-6"></div>
        </div>
        <div class="row">
            <div class="col-sm-12">
                <table width="100%" class="table table-striped table-bordered table-hover dataTable no-footer dtr-inline" id="" role="grid" aria-describedby="dataTables-example_info" style="width: 100%;">
                    <thead>
                        <tr >
                            <th>No.</th>
                            <th>分类名称</th>
                            <th>所属</th>
                            <th>图片</th>
                            <th>状态</th>
                            <th>添加时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody> 
                        <foreach name="list" item="val">
                            <tr class="odd gradeX" align="center">
                                <td>{++$i}</td>
                                <td>{$val.name}</td>
                                <td>{$val['pname'] == '' ? '顶级分类' : $val['pname']}</td>
                                <td>
                                    <if condition="$val['img'] EQ '' ">
                                         没有图片
                                        <else />
                                        <img width="100" src="__ROOT__{$val['img']}" alt="">
                                    </if>
                                </td>
                                <td class="center qj">{$val['state'] == 1 ? '启用' : '隐藏'}</td>
                                <td class="center">{:date('Y-m-d H:i:s',$val['time'])}</td>
                                   <td class="center">
                                    <a href="{:U('sel',['id'=>$val['id'],'pid'=>$val['pid']])}" class="btn btn-outline btn-primary">查看子类</a>
                                     <a href="javascript:void (0)" class="btn btn-outline btn-success" onclick="qj(this,{$val['id']})">{$val['state'] == 1 ? '隐藏' : '启用'}</a>
                                    <a href="{:U('edit',['id'=>$val['id']])}" class="btn btn-outline btn-primary">编辑</a>
                                    <a href="{:U('del',['id'=>$val['id']])}" class="btn btn-outline btn-danger" onclick="del(this,{$val['id']})"class="del">删除</a>
                                </td>
                            </tr>
                        </foreach>
                    </tbody> 
                </div>
            </div>
        </table>
            <div class="row"><div class="col-sm-6"></div>
                <div class="col-sm-6">
                    <div class="dataTables_paginate paging_simple_numbers" id="dataTables-example_paginate">
                        <div class="pages" style="margin: 0px auto;text-align: center;">
                            {$page}
                        </div>
                    </div>
                </div>
            </div>

                            <!-- /.table-responsive -->
                        
                        </div>
                        <!-- /.panel-body -->
                    </div>
</block>
<block name="js">
    <script>
        function qj(tha,id) {
            $.ajax({
                type: 'POST',
                data:{id:id},
                url: '{:U("qj")}',
                success: function(dat){
                    console.dir(dat);
                    dat = JSON.parse(dat);
                    alert(dat.message)
                    if(dat.state == 1)
                    {
                        $(tha).html('隐藏')
                        $(tha).parent().parent().find('.qj').html('启用')
                    }else if(dat.state == 2){
                        $(tha).html('启用')
                        $(tha).parent().parent().find('.qj').html('隐藏')
                    }
                },
                error:function () {
                    alert('系统错误')
                }
            })
        }
    //    function del(dat,id){
    //         confirm("确定删除？删除后将无法恢复。");
    //       $.ajax({
    //         type: "post",
    //         url: "{:U('Type/del')}",//url为tp方法（控制器/方法）
    //         data:{id:id},
    //         success: function(json) {
    //             alert(json);
    //         //  var obj = eval('(' + json + ')');//返回回来的json转化为js对象
    //         //   if (parseInt(obj.counts) > 0) {
    //         //     alert(obj.des);
    //         //     location.reload();
    //         //    } else {
    //         //     alert(obj.des);
    //         //    }
    //         //   },
    //         // error: function(XMLHttpRequest, textStatus) {
    //         //    alert("页面请求错误，请检查重试或联系管理员！\n" + textStatus);
    //         //  }
    //        });
        
      
    // }
    </script>
</block>